package com.qifan.alb2b.dao;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Repository;

import com.cqcis.base.orm.jdbc.JdbcUtil;
import com.qifan.alb2b.domain.CityInfoDomain;
import com.qifan.alb2b.domain.RouteDetailInfoDomain;
import com.qifan.alb2b.util.Page;

/**
 * 旅游线路CURD
 * @author hc24
 *
 */
@Repository
public class RouteDetailInfoDao extends BaseDao {
	private final static Log logger=LogFactory.getLog(RouteDetailInfoDao.class);
	
	/**
	 * 根据线路id查询线路详情
	 * @param routeId
	 * @return
	 */
	public Page query(String routeId){
		logger.debug("线路详情查询");
		/* 构建sql */
		StringBuilder sql=new StringBuilder();
		List<Object> params=new ArrayList<Object>();
		sql.append("select * from routeDetailInfo where routeId=? order by whichDay asc");
		params.add(routeId);
		return super.queryObjByPage(sql.toString(), 100, 1, params, RouteDetailInfoDomain.class);
	}
	
	public RouteDetailInfoDomain getDetailById(String detailId){
		String sql="select * from routeDetailInfo where detailId=?";
		List<RouteDetailInfoDomain> list=JdbcUtil.queryForList(this, RouteDetailInfoDomain.class, sql, detailId);
		if(list.size()>0)
			return list.get(0);
		return null;
	}
	
	public void add(RouteDetailInfoDomain routeDetailInfoDomain){
		super.addObj(routeDetailInfoDomain);
	}
	
	public void update(RouteDetailInfoDomain routeDetailInfoDomain){
		super.updateObj(routeDetailInfoDomain, "detailId");
	}
	
	/**
	 * 批量删除
	 * @param ids
	 */
	public void delete(String[] ids){
		StringBuilder delSql=new StringBuilder();
		delSql.append("delete from routeDetailInfo where detailId in(");
		for(int i=0;i<ids.length-1;i++){
			delSql.append("?,");
		}
		delSql.append("?)");
		logger.debug("删除sql："+delSql+"["+ids+"]");
		this.getJdbcTemplate().update(delSql.toString(), ids);
	}
	
	/**
	 * 根据线路id删除相应的线路详细
	 * @param routeId
	 */
	public void delete(String routeId){
		String delSql="delete from routeDetailInfo where routeId=?";
		logger.debug("删除sql："+delSql+"["+routeId+"]");
		this.getJdbcTemplate().update(delSql, routeId);
	}
}
